
package suncertify.db;

import java.util.logging.Logger;
import java.util.logging.Level;

/**
 *
 * @author jshah
 * Class which contains several inner classes representing the Exceptions thrown by DB Server
 */
public class DbExceptions extends java.lang.Exception {


    Logger logger = Logger.getLogger(DbExceptions.class.getName());
    /**
     * DuplicateKeyException is thrown when an attempt is made to create a record same as existing record in DBFile, for this project
     * only Name and Location fields are the criteria hence there should not be any two records with same name and location
     */
    public class DuplicateKeyException extends DbExceptions {

        /**
         * default constructor for <code>DuplicateKeyException</code>
         */
        DuplicateKeyException() {
            logger.log(Level.SEVERE,"DUPLICATE KEY EXCEPTION");
        }

        /**
         * constructor for <code>DuplicateKeyException</code> which takes a String argument for a message to be displayed when the Exception is thrown
         * @param desc      A String message to be displayed when an Exception is thrown
         */
        DuplicateKeyException(String desc){
            logger.log(Level.SEVERE,desc);
        }
    }

    /**
     * Exception to be thrown when the Record is not present in a DBFile
     */
    public class RecordNotFoundException extends DbExceptions{
        /**
         * default constructor for the <code>RecordNotFoundException</code>
         */
        RecordNotFoundException() {
            logger.log(Level.SEVERE,"RECORD NOT FOUND");
        }
        /**
         * A constructor with a String argument which can take a message to be displayed when an <code>RecordNotFoundException</code> is thrown
         * @param desc          A String message do be displayed when and Exception is thrown
         */
        RecordNotFoundException(String desc){
            logger.log(Level.SEVERE,desc);
        }
    }

    /**
     * An Exception thrown if an attempt is made to book a record which is already booked
     */
    public class RecordBookedException extends DbExceptions {

        /**
         * default constructor for <code>RecordBookedException</code>
         */
        RecordBookedException(){
            logger.log(Level.SEVERE,"RECORD BOOKED EXCEPTION");
        }
        /**
         * constructor with a String argument to display custom message when the Exception is thrown
         * @param desc          custom message to be displayed when the Exception is thrown
         */
        RecordBookedException(String desc){
            logger.log(Level.SEVERE,desc);
        }

    }

    /**
     * An Exception to be thrown if the <code>magicookie</code> of the DBFile supplied by the CSR does not match the expected
     * <code>magiccookie</code>
     */
    public class DBFileSanityException extends DbExceptions {

        /**
         * default constructor for <code>DBFileSanityExceptino</code>
         */
        DBFileSanityException(){
            logger.log(Level.SEVERE,"DBFile Sanity Exception, Corrupted or tempered DB File");
        }

        /**
         * constructor with a String argument to display custom message when the Exception is thrown
         * @param desc          custom message to be displayed when the Exception is thrown
         */
        DBFileSanityException(String desc){
            logger.log(Level.SEVERE,desc);
        }

    }
}

